//
//  HSListCell.m
//  HolyShit
//
//  Created by Robin on 2017/3/24.
//  Copyright © 2017年 HolyShit. All rights reserved.
//

#import "HSListCell.h"
#import "HSListModel.h"


@interface HSListCell ()

//纯文字
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *descLb;
@property (nonatomic, strong) UIImageView *coverImgV;

@end

@implementation HSListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    [self my_setSelectedBg];
    self.backgroundColor = WHITE_COLOR;
    self.width = ScreenWidth;
    [self addSubview:self.coverImgV];
    [self addSubview:self.titleLb];
    [self addSubview:self.timeLb];
    if (ListType == 1) {
        [self.coverImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(10);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(65);
        }];
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.coverImgV.mas_right).offset(10);
            make.top.equalTo(self.coverImgV.mas_top);
            make.right.mas_equalTo(-15);
        }];
        [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.coverImgV.mas_bottom);
            make.right.mas_equalTo(-10);
        }];
    }
    else{
        self.descLb = [UILabel labelWithFont:MYFont(Font30) color:HEXCOLOR(HSColorGray)];
        [self addSubview:self.descLb];
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(15);
            make.right.mas_equalTo(-15);
        }];
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.titleLb);
            make.top.equalTo(self.titleLb.mas_bottom).offset(8);
        }];
        [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.titleLb);
            make.bottom.mas_equalTo(-10);
        }];
        [self.coverImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.timeLb.mas_top).offset(-10);
            make.left.right.equalTo(self.titleLb);
            make.height.mas_equalTo(188);
        }];
    }
}

- (void)setModel:(HSListModel *)model
{
    _model = model;
    self.titleLb.text = model.title;
    [self.coverImgV my_setImage:model.imgsrc];
    self.timeLb.text = model.ptime;//[NSString stringWithFormat:@"%lu跟帖", model.replyCount];
    if (ListType != 1) {
        self.descLb.text = model.digest;
    }
}


- (UIImageView *)coverImgV
{
    if (!_coverImgV) {
        _coverImgV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 100, 75) imageType:MYImageTypePic];
    }
    return _coverImgV;
}

- (UILabel *)titleLb
{
    if (!_titleLb) {
        _titleLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font34) color:HEXCOLOR(HSColorBlack)];
        _titleLb.numberOfLines = ListType == 1 ? 2 : 1;
        _titleLb.lineBreakMode = NSLineBreakByTruncatingTail;
    }
    return _titleLb;
}

- (UILabel *)timeLb
{
    if (!_timeLb) {
        _timeLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font26) color:HEXCOLOR(HSColorGray)];
    }
    return _timeLb;
}

@end
